<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="112px">
      <el-form-item label="访客名称" prop="visitorName">
        <el-input
          v-model="queryParams.visitorName"
          placeholder="请输入访客名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="访问目的" prop="visitPurpose">
        <el-input
          v-model="queryParams.visitPurpose"
          placeholder="请输入访问目的"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option label="男" value="男" />
          <el-option label="女" value="女" />
        </el-select>
      </el-form-item>
      <el-form-item label="访客联系电话" prop="visitorPhone">
        <el-input
          v-model="queryParams.visitorPhone"
          placeholder="请输入访客联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号码" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否接触过" prop="touch">
        <el-select v-model="queryParams.touch" placeholder="请选择是否接触过" clearable size="small">
          <el-option
            v-for="dict in touchOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="近期发烧、干咳" prop="fever">
        <el-select v-model="queryParams.fever" placeholder="请选择近期发烧、干咳" clearable size="small">
          <el-option
            v-for="dict in feverOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否接种" prop="vaccination">
        <el-select v-model="queryParams.vaccination" placeholder="请选择是否接种" clearable size="small">
          <el-option
            v-for="dict in vaccinationOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="乘坐交通工具" prop="vehicle">
        <el-select v-model="queryParams.vehicle" placeholder="请选择乘坐交通工具" clearable size="small">
          <el-option
            v-for="dict in vehicleOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="户籍" prop="censusRegister">
        <el-input
          v-model="queryParams.censusRegister"
          placeholder="请输入户籍"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['energy:mjVisitor:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['energy:mjVisitor:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['energy:mjVisitor:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:mjVisitor:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mjVisitorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="Id" align="center" prop="id" />-->
      <el-table-column label="访客名称" align="center" prop="visitorName" />
      <el-table-column label="访问目的" align="center" prop="visitPurpose" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="访客联系电话" align="center" prop="visitorPhone" />
      <el-table-column label="身份证号码" align="center" prop="idCard" />
      <el-table-column label="到访人数" align="center" prop="visitorNumber" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="是否接触过重点疫区返/抵渝人员" align="center" prop="touch" :formatter="touchFormat" />
      <el-table-column label="近期身体无发烧、干咳人员" align="center" prop="fever" :formatter="feverFormat" />
      <el-table-column label="是否接种新冠疫苗" align="center" prop="vaccination" :formatter="vaccinationFormat" />
      <el-table-column label="体温℃" align="center" prop="temperature" />
      <el-table-column label="乘坐交通工具" align="center" prop="vehicle" :formatter="vehicleFormat" />
      <el-table-column label="户籍" align="center" prop="censusRegister" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['energy:mjVisitor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['energy:mjVisitor:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改访客管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="126px">
        <el-form-item label="访客名称" prop="visitorName">
          <el-input v-model="form.visitorName" placeholder="请输入访客名称" />
        </el-form-item>
        <el-form-item label="访问目的" prop="visitPurpose">
          <el-input v-model="form.visitPurpose" placeholder="请输入访问目的" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option label="男" value="男" />
            <el-option label="女" value="女" />
          </el-select>
        </el-form-item>
        <el-form-item label="访客联系电话" prop="visitorPhone">
          <el-input v-model="form.visitorPhone" placeholder="请输入访客联系电话" />
        </el-form-item>
        <el-form-item label="身份证号码" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="到访人数" prop="visitorNumber">
          <el-input v-model="form.visitorNumber" placeholder="请输入到访人数" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否接触过重点疫区返/抵渝人员">
          <el-radio-group v-model="form.touch">
            <el-radio
              v-for="dict in touchOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="近期身体无发烧、干咳人员">
          <el-radio-group v-model="form.fever">
            <el-radio
              v-for="dict in feverOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否接种新冠疫苗">
          <el-radio-group v-model="form.vaccination">
            <el-radio
              v-for="dict in vaccinationOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="体温℃" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入体温℃" />
        </el-form-item>
        <el-form-item label="乘坐交通工具" prop="vehicle">
          <el-select v-model="form.vehicle" placeholder="请选择乘坐交通工具">
            <el-option
              v-for="dict in vehicleOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="户籍" prop="censusRegister">
          <el-input v-model="form.censusRegister" placeholder="请输入户籍" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMjVisitor, getMjVisitor, delMjVisitor, addMjVisitor, updateMjVisitor } from "@/api/energy/mjVisitor";

export default {
  name: "MjVisitor",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 访客管理表格数据
      mjVisitorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否接触过重点疫区返/抵渝人员字典
      touchOptions: [],
      // 近期身体无发烧、干咳人员字典
      feverOptions: [],
      // 是否接种新冠疫苗字典
      vaccinationOptions: [],
      // 乘坐交通工具字典
      vehicleOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        visitorName: null,
        visitPurpose: null,
        sex: null,
        visitorPhone: null,
        idCard: null,
        visitorNumber: null,
        remark: null,
        touch: null,
        fever: null,
        vaccination: null,
        temperature: null,
        vehicle: null,
        censusRegister: null
      },
      // 表单参数
      form: {
        vaccination:0,
        fever:0,
        touch:0,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_yes_no01").then(response => {
      this.touchOptions = response.data;
    });
    this.getDicts("sys_yes_no01").then(response => {
      this.feverOptions = response.data;
    });
    this.getDicts("sys_yes_no01").then(response => {
      this.vaccinationOptions = response.data;
    });
    this.getDicts("sys_comom_vehicle").then(response => {
      this.vehicleOptions = response.data;
    });
  },
  methods: {
    /** 查询访客管理列表 */
    getList() {
      this.loading = true;
      listMjVisitor(this.queryParams).then(response => {
        this.mjVisitorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否接触过重点疫区返/抵渝人员字典翻译
    touchFormat(row, column) {
      return this.selectDictLabel(this.touchOptions, row.touch);
    },
    // 近期身体无发烧、干咳人员字典翻译
    feverFormat(row, column) {
      return this.selectDictLabel(this.feverOptions, row.fever);
    },
    // 是否接种新冠疫苗字典翻译
    vaccinationFormat(row, column) {
      return this.selectDictLabel(this.vaccinationOptions, row.vaccination);
    },
    // 乘坐交通工具字典翻译
    vehicleFormat(row, column) {
      return this.selectDictLabel(this.vehicleOptions, row.vehicle);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        visitorName: null,
        visitPurpose: null,
        sex: null,
        visitorPhone: null,
        idCard: null,
        visitorNumber: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null,
        touch: "0",
        fever: "0",
        vaccination: "0",
        temperature: null,
        vehicle: null,
        censusRegister: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加访客管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMjVisitor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改访客管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMjVisitor(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMjVisitor(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除访客管理编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delMjVisitor(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('energy/mjVisitor/export', {
        ...this.queryParams
      }, `energy_mjVisitor.xlsx`)
    }
  }
};
</script>
